<div class="modal fade bs-modal-md" id="modelContent">
	<div class="modal-dialog modal-md">
        <div class="modal-content"></div>
    </div>
</div> 
<div class="portlet box green">
	<div class="portlet-title">
		<div class="caption">
			<i class="fa fa-search"></i>查询内容
		</div>
		<div class="tools">
			<a href="javascript:;" class="collapse right" data-original-title="" title=""> </a>
		</div>
		<div class="actions">
			<a href="javascript:;" class="btn white btn-sm ajax-search"><i class="fa fa-search"></i>查询 </a> 
			<a href="javascript:;" class="btn white btn-sm search-reset"><i class="fa fa-eraser"></i>清除 </a>
		</div>
	</div>
	<div class="portlet-body form" style="display: block;">
		<form action="/productSale/list" class="form-horizontal" method="get" id="searchForm" onsubmit="return false">
 			<div class="form-body">
				<div class="form-group ">
					<div class="col-md-6">
						<div class="col-md-4">
							<label class="control-label col-md-3">货品：</label>
							<div class="col-md-8">
								<input class="form-control" type="text" name="product"   placeholder="输入货品名称或编码" value="$!product">
							</div>
						</div>
						<div class="col-md-4">
							<label class="control-label col-md-3">SKU：</label>
							<div class="col-md-8">
								<input class="form-control" type="text" name="sku"  placeholder="输入货品SKU编码"   value="$!sku">
							</div>
						</div>
						<div class="col-md-4">
							<label class="control-label col-md-3">分类：</label>
							<div class="col-md-8">
	 							<select name="categoryId" data-size="8" data-live-search="true" class="form-control bs-select">
	 								<option value="">请选择</option>
	 								#foreach($category in $!categoryList)
	 								<option  #if($!categoryId == $!category.id)  selected="selected" #end value="$!category.id">$!category.name</option>
	 								#end
	 							</select>
							</div>
						</div>
					</div>
					<div class="col-md-6">
						 <div class="col-md-4">
						 	<label class="control-label col-md-3">品牌:</label>
						 	<div class="col-md-8">
						 		<select name="brandId"  data-size="8" data-live-search="true" class="form-control bs-select">
						 			<option selected  value="">请选择</option>
						 			#foreach($brand in $!brandList)
	 								<option #if($!brandId == $!brand.id) selected="selected" #end value="$!brand.id">$!brand.name</option>
	 								#end
	 							</select>
						 	</div>
						 </div>
					 	<div class="col-md-4">
						 	<label class="control-label col-md-3">标签:</label>
						 	<div class="col-md-8">
						 	 	<select data-live-search="true" data-size="8" class="form-control bs-select" name="label">
						 	 	<option  selected  value="">请选择</option>
						 	 	#foreach($label  in $!pLabelList)
						 	 		<option #if($!label.name == $!labels ) selected="selected" #end value="$label.name">$label.name</option>
						 	 	#end
						 	 	</select>
						 	</div>
						</div> 
					</div>
				</div>
				<div class="form-group ">
					<div class="col-md-6">
						 <div class="col-md-4">
						 	<label class="control-label col-md-3">销量:</label>
						 	<div class="col-md-4">
						 		<input class="form-control" type="number" name="sales"   value="$!sales">
						 	</div>
						 	<div class="col-md-1">～</div>
						 	<div class="col-md-4">
						 		<input  class="form-control" type="number" name="sales2"  value="$!sales2">
						 	</div>
						 </div>
						 <div class="col-md-4">
						 	<label class="control-label col-md-3">售价:</label>
						 	<div class="col-md-4">
						 		<input class="form-control" type="number" name="price"   value="$!price">
						 	</div>
						 	<div class="col-md-1">～</div>
						 	<div class="col-md-4">
						 		<input  class="form-control" type="number" name="price2"  value="$!price2" >
						 	</div>
						 </div>
						 <div class="col-md-4">
						 	<label class="control-label col-md-3">库存:</label>
						 	<div class="col-md-4">
						 		<input class="form-control" type="number" name="inventory"   value="$!inventory">
						 	</div>
						 	<div class="col-md-1">～</div>
						 	<div class="col-md-4">
						 		<input  class="form-control" type="number" name="inventory2"  value="$!inventory2" >
						 	</div>
						 </div> 
					 </div>
					 <div  class="col-md-6" >
					 	<!--  <div class="col-md-5"> -->
						 	<label class="control-label col-md-3">创建时间:</label>
						 	<div class="col-md-4" style="width: 125px">
						 		<input style="background-color: white;" class="form-control" type="text" name="startTime" id="startTime" value="$!startTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
						 	</div>
						 	<div class="col-md-1">~</div>
						 	<div class="col-md-4" style="width: 125px;margin-left:-45px">
						 		<input  style="background-color: white;" class="form-control" type="text" name="endTime" id="endTime" value="$!endTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
					        </div> 
						<!--  </div> -->
					 </div>
				</div>
			</div>
		</form>
	</div>
</div>
<div class="portlet box green">
	<div class="portlet-title">
		<div class="caption">
			<i class="fa fa-cogs"></i>销售中的商品
		</div>
		<div class="tools">
			<a href="javascript:;" class="collapse" data-original-title="" title=""> </a>
		</div>
		<div class="actions">
			<a href="javascript:;"   class="btn white btn-sm delete-tab" ><i class="fa fa-trash"></i>批量删除</a>
			<a href="javascript:;"  class="btn white btn-sm soldOut-tab" ><i class="fa fa-cart-arrow-down"></i>下架</a>
			<div class="btn-group " >
				<button type="button" class="btn white btn-sm" data-toggle="dropdown"> 
					<i class="fa fa-qrcode"></i> 下载二维码  
				</button>
				<ul class="dropdown-menu pull-right" role="menu">
					<li>
						<a href="javascript:;" class="downQR-tab"  > <i class="fa fa-cube"></i> 指定商品二维码 </a>
					</li>
					<li>
						<a href="javascript:;" class="downQR-all"> <i class="fa fa-cubes"></i> 全部商品二维码 </a>
					</li>
				</ul>
			</div>
<!-- 		    <span class="btn white btn-file"> -->
<!-- 			    <span class="fileinput-new "><i class="fa fa-cloud-upload"></i>导入 </span> -->
<!-- 			    <input type="file" class="file import-tab" name="" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"> -->
<!-- 		    </span> -->
			<div class="btn-group " >
				<button type="button" class="btn white btn-sm " data-toggle="dropdown"> 
					<i class="fa fa-cloud-download"></i> 导出
				</button>
				<ul class="dropdown-menu pull-right" role="menu">
					<li>
						<a href="javascript:;" class="export-tab"> <i class="fa fa-cube"></i> 指定商品</a>
					</li>
					<li>
						<a href="javascript:;" class="export-all"> <i class="fa fa-cubes"></i> 全部商品</a>
					</li>
				</ul>
			</div>
			<a href="/productSale/goods?flag=1"   class="btn white btn-sm ajaxify" ><i class="fa fa-expand"></i>全部货品</a>
		</div>
	</div>
	<div class="portlet-body">
		<div class="form-group">
			<div class="alert alert-block alert-warning fade in">
                   <button type="button" class="close" data-dismiss="alert"></button>
                   <strong> 注：</strong>
                   <p> 1.销售中的货品指的是平台正在上架售卖的货品，若将货品下架，该货品进入“仓库中货品”下的“下架”列表中； 2.点击列表“操作”下的“复制新增”可创建相似货品；3.【全部规格】点点击后切换到【全部货品】列表相互切换。【货品列表】显示为相同货品名称的规格合集。 </p>
              </div>
		</div>
		<div class="table-container table-scrollable">
			<table class="table table-bordered table-hover icheck-table" id="productTable">
				<thead>
					<tr>
					 	<th style="width: 20px">
							<input type="checkbox" class="icheck group-icheck"/>
						</th>
						<th>序号</th>
						<th>商品名称</th>
						<th>分类</th>
						<th>品牌</th>
						<th>售价</th>
						<th>货品列表</th>
						<th>库存</th>
						<th>总销量</th>
						<th>标签</th>
						<th class="col-md-1" style="width:160px;">操作</th>
					</tr>
				</thead>
				<tbody>
					#foreach ($!item in $!pageProduct.result)
					#set($inventory = $!inventoryMap.get($!item))
					<tr class="odd gradeX pro_tr" >
						<td>
							<input type="checkbox" name="checkboxes" class="icheck" value="$!item.id" />
						</td>
						<td>
						<p style="margin: 0">$!velocityCount</p>
						</td>
						<td>
							<div style="display: inline-block;margin-left: 10px">
								<p style="margin: 0"><a href="$!portalHostDomain/product/$!item.id" title="$item.name" target="_blank">$item.name</a></p>
								
							</div>
						</td>
						<td>$!item.category.name</td>
						<td>$!item.brandName</td>
						<td>$item.salesPrice</td>
						<td><a href="#modelContent" thref="/product/skuList?productId=$!item.id" class="ajax-model-get" data-toggle="modal">查看</a></td>
						<td>$!inventory</td>
						<td>$!item.salesNum</td>
						#if($!item.lables)
						<td>$!item.lables</td>
						#else
						<td>$!item.salesMode</td>
						#end
						
						<td>
<!-- 						<!-- &product=$!product&sku=$!sku&categoryId=$!categoryId&brandId=$!brandId&label=$!label &sales=$!sales&sales2=$!sales2&price=$!price&price2=$!price2&inventory=$!inventory&inventory2=$!inventory2&startTime=$!startTime&endTime=$!endTime&_=1525664725188&pageNo=$!pageNo -->
							
                               <a class="btn green btn-outline btn-sm ajaxify" code="product.edit" href="/product/edit?id=$!item.id&resultUrl=$!resultUrl&$!queryString&pageNo=$!pageProduct.pageNo">
								<i class="fa fa-edit"></i>	修改
							</a>
							<a class="btn green btn-outline btn-sm ajax-model-get" data-attrValueId="" href="#modelContent" thref="/attr/specificationsadd?productId=$!item.id" data-toggle="modal">
								<i class="fa fa-edit"></i> 关联
							</a>

						</td>
					</tr>
					#end
				</tbody>
			</table>
		</div>
		#set($page=$pageProduct)
		#set($pageUrl="/productSale/list.do?$!queryString&pageNo=") 
		#parse("_page.htm")
	</div>
	<div id="qrMl" style="display: none;top: 50%; right: 50%; z-index: 100; position: absolute; background-color: #fff; width: 200px;height: 200px;box-shadow: 5px 5px rgba(102,102,102,.1);border: 1px solid #eee;">
		<button type="button" class="close close-click" style="margin: 10px;"></button>
		<img  style="width: 151px;height: 151px;margin-left: 20px">
	</div>
	<form id="downfile" action="" class="hide" method="POST">
		<input type="hidden" name="pid" id="pid" value="">
		<input type="hidden" name="flag" value="$!flag">
		<button type="submit"></button>
	</form>
</div>
<script type="text/javascript" src="/assets/scripts/views-permission.js"></script>
<script type="text/javascript" src="/assets/scripts/views-icheck.js"></script>
<script type="text/javascript">
    function formatAttr(repo) {
        if (repo.loading) {
            return repo.text;
        }
        var markup = "<div class='select2-result-repository clearfix'>"
            + "<div class='select2-result-repository__meta' style='margin-left: 4px'>"
            + "<div class='select2-result-repository__title'>" + repo.id+"</div>"
            + "<div class='select2-result-repository__description'>"+ repo.name + "</div>"
            +"</div>"
            +"</div>";
        return markup;
    }
    function formatRepoSelection(repo) {
        return   repo.id;
    }
	ComponentsSelect2.initWithSearch();
     $("input[name=code]").focus();
     var pageContentBody = $('.page-content .page-content-body');
     
     function getcbvalue(){
 		var array = new Array()
 		var target= $("input[name='checkboxes']");
 		//循环加入数组
 		
 			$.each(target,function(i,v){
 				if(v.checked){
 					array.push($(v).val());
 				}
 			});
		 	return array; 
	  }
     
     /**
      * 批量删除
      */
     $(".delete-tab").click(function(){
    	  var pIdArray= getcbvalue();
    	  if(pIdArray.length>0){
      		bootbox.setLocale("zh_CN");
    		bootbox.confirm("确定删除这些商品吗？", function(state) {
    			if(state){
   			   	 $.post("/productSale/deleteProduct",{"pIdArray":pIdArray},function(result){
			        	if(result.code==0){
			        		toastr.success(result.msg);
			       			pageContentBody.load("/productSale/list");
			       		}else {
			       			toastr.warning(result.msg);
			       		}
				   },"json");
    			}
    		});
    	  }
     })
     /**
      * 批量下架
      */
     $(".soldOut-tab").click(function(){
    	var pIdArray= getcbvalue();
    	if(pIdArray.length>0){
    		bootbox.setLocale("zh_CN");
    		bootbox.confirm("确定下架这些商品吗？", function(state) {
    			if(state){
    			   	 $.post("/productSale/solout",{"pIdArray":pIdArray},function(result){
    			        	if(result.code==0){
    			        		toastr.success(result.msg);
    			       			pageContentBody.load("/productSale/list");
    			       		}else {
    			       			toastr.warning(result.msg);
    			       		}
    				   },"json");
    			}
    		});
   		}else{
   			toastr.warning("请勾选需要下架的商品！");
   		}
     })
     /**
      * 下载二维码
      */
     $(".downQR-tab").click(function(){
    	 var pIdArray= getcbvalue();
    	 if(pIdArray.length>0){
   		    $("#pid").val(pIdArray);
   		    $("#downfile").attr("action","/productSale/downloadQRCode");
   			$("#downfile").submit();
    	 }else{
    		 toastr.warning("请选择商品");
    	 }
     })
     /**
      * 下载全部二维码
      */
     $(".downQR-all").click(function(){
		    $("#pid").val("");
   		    $("#downfile").attr("action","/productSale/downloadQRCode");
   			$("#downfile").submit();
     })
     /**
      *
      * 导入excel 
      */
     $(".import-tab").change(function(){
    	 var source=$(this);
    	 var file = source.context.files[0];
    	 var formdata = new FormData();  
    	 formdata.append('file',file);
 	 	$.ajax({
 			url : '/productSale/importExcel',
 			type : 'POST',
 			data : formdata,
 			async : false,
 			cache : false,
 			contentType : false,
 			processData : false,
 			dataType :"JSON",
 			success : function(data) {
 				if(data.code == 0){
 					 toastr.success(data.msg);
 					pageContentBody.load("/productSale/list");
 				}else{
 					 $.each(data,function(i,v){
 						 toastr.warning(v);
 					 })
 				}
 			} 
 		});
    	 
     })
     /**
      *
      * excel 导出
      */
     $(".export-tab").click(function(){
    	 var pIdArray= getcbvalue();
    	 if(pIdArray.length>0){
   		    $("#pid").val(pIdArray);
   		    $("#downfile").attr("action","/productSale/downloadExcel");
   			$("#downfile").submit();
    	 }else{
    		 toastr.warning("请选择商品");
    	 }
     })
     /*
      *  excel 导出全部
      */
     $(".export-all").click(function(){
	    	$("#pid").val("");
  		    $("#downfile").attr("action","/productSale/downloadExcel");
  			$("#downfile").submit();
     })
     
     /**
      *
      * 获得 鼠标点击坐标
      */
     function getMousePos(event) {
            var e = event || window.event;
            var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
            var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
            var x = e.pageX || e.clientX + scrollX;
            var y = e.pageY || e.clientY + scrollY;
            return { 'x': x, 'y': y };
      }
     /**
     * 点击二维码 查看事件
     *  
     */
     var record = "" ;
     $(".qrCheck").click(function(event){
    	  var ptId=$(this).attr("ptId");
    	  var target= $("#qrMl");
    	  target.toggle();
    	  if(record != ptId){
    		  target.show();
    		  record = ptId;
    	  } 
     	  $.get("/productSale/getQrCodeImg",{"ptId":ptId},function(result){
     		  $("#qrMl > img").attr("src",result);
         	  var m = getMousePos(event);
         	  target.css("top",(m.y-270)+"px");
         	  target.css("left",(m.x-30)+"px");
     	  })
     })
 	 /**
     * 二维码窗口关闭
     *  
     */
     $(".close-click").click(function(){
    	 $("#qrMl").hide();
     })
</script>
